﻿using UnityEditor;
using UnityEngine;
using System.Collections;

[CustomEditor(typeof(PUEXEventHandle))]
public class PUEXEventHandleEditor : Editor {

	public override void OnInspectorGUI ()
	{
		serializedObject.Update ();

		var handleNameProperty = serializedObject.FindProperty ("handleName");
		var eventTypeProperty = serializedObject.FindProperty ("eventType");
		var eventNameProperty = serializedObject.FindProperty ("eventName");
		var handleTypeProperty = serializedObject.FindProperty ("handleType");
		var intValueProperty = serializedObject.FindProperty ("intValue");
		var floatValueProperty = serializedObject.FindProperty ("floatValue");
		var stringValueProperty = serializedObject.FindProperty ("stringValue");

		EditorGUILayout.PropertyField (handleNameProperty);

		EditorGUILayout.PropertyField (eventTypeProperty, new GUIContent("If"));
		var newEventType = (PUEXHandle.EvnetType)eventTypeProperty.enumValueIndex;
		switch (newEventType) {
		case PUEXHandle.EvnetType.ET_NOTIFY_EVENT: {
			EditorGUILayout.PropertyField (eventNameProperty, new GUIContent("Event Name"));
			break;
		}
		default:
			break;
		}

		EditorGUILayout.PropertyField (handleTypeProperty, new GUIContent("Then"));
		var newHandleType = (PUEXEventHandle.HandleType)handleTypeProperty.enumValueIndex;
		switch (newHandleType) {
		case PUEXEventHandle.HandleType.HT_EMITTER_ENABLE: {
			EditorGUILayout.PropertyField (stringValueProperty, new GUIContent("Emitter Name"));
			break;
		}
		case PUEXEventHandle.HandleType.HT_EMITTER_DISABLE: {
			EditorGUILayout.PropertyField (stringValueProperty, new GUIContent("Emitter Name"));
			break;
		}
		case PUEXEventHandle.HandleType.HT_EMITTER_EMIT: {
			EditorGUILayout.PropertyField (stringValueProperty, new GUIContent("Emitter Name"));
			EditorGUILayout.PropertyField (intValueProperty, new GUIContent("Emit Count"));
			break;
		}
		case PUEXEventHandle.HandleType.HT_AFFECTOR_ENABLE: {
			EditorGUILayout.PropertyField (stringValueProperty, new GUIContent("Affector Name"));
			break;
		}
		case PUEXEventHandle.HandleType.HT_AFFECTOR_DISABLE: {
			EditorGUILayout.PropertyField (stringValueProperty, new GUIContent("Affector Name"));
			break;
		}
		case PUEXEventHandle.HandleType.HT_AFFECTOR_TRIGGER: {
			EditorGUILayout.PropertyField (stringValueProperty, new GUIContent("Affector Name"));
			EditorGUILayout.PropertyField (floatValueProperty, new GUIContent("Duration Time"));
			break;
		}
		case PUEXEventHandle.HandleType.HT_NOTIFY_EVENT: {
			EditorGUILayout.PropertyField (stringValueProperty, new GUIContent("Event Name"));
			break;
		}
		case PUEXEventHandle.HandleType.HT_DISPATCH_EVENT: {
			EditorGUILayout.PropertyField (stringValueProperty, new GUIContent("Event Name"));
			break;
		}
		case PUEXEventHandle.HandleType.HT_SPAWN_SUBSYSTEM: {
			EditorGUILayout.PropertyField (stringValueProperty, new GUIContent("Sub System Name"));
			break;
		}
		}

		serializedObject.ApplyModifiedProperties ();
	}

}
